<?php


namespace app\admin\controller;


use think\admin\Controller;
use think\admin\service\SystemService;

class Basic extends Controller
{

    /**
     * 展示页面
     * @auth true
     */
    public function index()
    {
        $this->title = '运营参数配置';
        $this->fetch();
    }
    /**
     * 修改运营参数
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function system()
    {
        $this->_applyFormToken();
        if ($this->request->isGet()) {
            $this->title = '修改运营参数';
            $this->fetch();
        } else {
            foreach ($this->request->post() as $name => $value) sysconf($name, $value);
            $this->success('修改系统参数成功！', '#' . url("admin/basic/index"));
        }
    }

    /**
     * 修改文件存储
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function storage()
    {
        $this->_applyFormToken();
        if ($this->request->isGet()) {
            $this->type = input('type', 'local');
            $this->fetch("storage-{$this->type}");
        } else {
            $post = $this->request->post();
//            if (!empty($post['storage']['allow_exts'])) {
//                $exts = array_unique(explode(',', strtolower($post['storage']['allow_exts'])));
//                if (sort($exts) && in_array('php', $exts)) $this->error('禁止上传可执行的文件！');
//                $post['storage']['allow_exts'] = join(',', $exts);
//            }
            foreach ($post as $name => $value) sysconf($name, $value);
            $this->success('操作成功！');
        }
    }
}